<?php
!defined('ROOT_DIR') && exit('Access Denied');

class Control extends Base {

	function __construct() {
		$_SESSION['lang'] = 'en';
		$this->init();
		$this->load('defalut');
		$this->load('cache');
	}

	function onIndex() {
		$id = get_vars('id', 1);
		
		$id = $_ENV['defalut']->test($id);
		loader('pagination');
		$base_url = 'index.php';
		$num_items = 215;
		$per_page = 10;
		$cur_page = get_vars('page',1);
		$start_item = get_vars('start',1);
		$style_page = Pagination::stylePage($base_url, $num_items, $per_page, $cur_page);
		$style_start = Pagination::styleStart($base_url, $num_items, $per_page, $start_item);
		echo $style_page['page_string']."<br>";
		echo $style_start['page_string'];
		//var_dump($style_page);
		//var_dump($style_start);
		
		$arr = $_ENV['cache']->arrList();
		$member_list = $_ENV['cache']->memberList();
		print_r($member_list);
		
		$row = $_ENV['cache']->row();
		var_dump($row);
		$this->view->assign('title','测试标题');
		$this->view->display('test');
	}

	function onDbcache() {
		  $_ENV['cache']->dbcache();
	}
	
	function onXxx(){
		$string = "Applied Cryptography, by Bruce Schneier, is a wonderful cryptography reference.";
		$key = "Four score and twenty years ago";
			
		$cipher_alg = MCRYPT_RIJNDAEL_128;
		$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,MCRYPT_MODE_ECB), MCRYPT_RAND);
		print "Original string: $string";
		$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_CBC, $iv);
		print "Encrypted string: ".bin2hex($encrypted_string);
		$decrypted_string = mcrypt_decrypt($cipher_alg, $key, $encrypted_string, MCRYPT_MODE_CBC, $iv);
		print "Decrypted string: ".$decrypted_string;
	}
	
	function onUrl()
	{
		$url_arr = array("page"=>2, "start"=>100);
		echo $this->sef->buildLink($url_arr);
	}
	
	function onResize()
	{
		echo "test";
		
		$imagename = "test.jpg";
		/**
		if(!$_FILES['filename']['size'] == 0){
			loader('image');
			$image = new ResizeImage($_FILES['filename']['tmp_name']);
			$image->setMaxHeight(75);
			$image->setMaxWidth(75);
			$image->setJpegQuality(90);
			$image->setOutputType(IMAGETYPE_JPEG);
			$image->resize(ResizeImage::BEST_FIT);
			$image->saveThumbnail(DATA_DIR.'upload/thumbs/'.$imagename);
		}
		*/
		$waterimagename = 'waterimage.jpg';
		if(!$_FILES['filename']['size'] == 0 && !$_FILES['waterfilename']['size'] == 0){
			loader('image');
			$image = new ResizeImage($_FILES['filename']['tmp_name']);
			$image->setMaxHeight(400);
			$image->setMaxWidth(300);
			$image->setJpegQuality(90);
			$image->setOutputType(IMAGETYPE_JPEG);
			$image->setWaterImageInfo($_FILES['waterfilename']['tmp_name']);
			//$image->setWaterTextInfo("test","#000000","10"); 
			$image->watermark(ResizeImage::BEST_FIT, 'BR');
			$image->saveWatermark(DATA_DIR.'upload/thumbs/'.$waterimagename);
		}
		$this->view->assign('imagesrc', DATA_URL.'upload/thumbs/'.$imagename);
		$this->view->assign('waterimagesrc', DATA_URL.'upload/thumbs/'.$waterimagename);
		$this->view->display('upload');
	}

}

?>